
/**
 * Module dependencies.
 */

var express = require('express');
var routes = require('./routes');
var user = require('./routes/user');
var http = require('http');
var path = require('path');

var app = express();

var gcm = require('node-gcm');


var apikey = 'AIzaSyDQMvNTc5NdTzvbfMgJ3M2I39l967UFZag';

var registrationIds = [];


var randomstring = require("randomstring");

var random = randomstring.generate(7);

// or with object values
var message = new gcm.Message({
  collapseKey: 'demo',
  delayWhileIdle: true,
  timeToLive: 3,
  data: {
    key1: 'message1',
    key2: 'message2'
  }
});

var sender = new gcm.Sender(apikey);


// At least one required
registrationIds.push('APA91bEi9UB8baJKw-aPnFTJlzsDnm6l2baOL7fXYVrmx5U6AFh46We5DByamxlZ4ZTBU-FwSiRctCpuajPfZUKafUf9rO5G2HAiws6ePls8ZRKkKnD8yUxL_R4QoHCfeEGKGlk8_rjo4WclntsEA0ocnrVk60Op2g');


/**
 * Params: message-literal, registrationIds-array, No. of retries, callback-function
 **/
sender.send(message, registrationIds, 4, function (err, result) {
  console.log(result);
});



// all environments
app.set('port', process.env.PORT || 80);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

app.get('/', routes.index);
app.get('/users', user.list);

http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});
